Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • eventstudy2 (Thomas Kaspereit*)

    Greetings everyone!

    I am trying to conduct an event study using stata and I am using the command eventstudy2 (Thomas Kaspereit ) . I am currently stuck on an error and unable to fix it.

    The error is as follows :
    "variables date __000005 do not uniquely identify observations in the using data" . I have tried to remove duplicates and yet it does not work

    My full sample is 255 companies and 65,059 observations.

    I am happy to provide my sample data if someone needs it.

    Look forward to the stata community base here to help me.

    Thanks very much!






    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str43 security_id int date double(security_return market_returns) byte market_id
    "NESTLE 'N'" 20030 -.0071276139242321 -.0097911745876343 1
    "NESTLE 'N'" 20031                  0  -.003852391383751 1
    "NESTLE 'N'" 20032  .0085470605784583  .0142532617362586 1
    "NESTLE 'N'" 20033  .0021253993123135  .0023391823531722 1
    "NESTLE 'N'" 20034 -.0049663103139173 -.0053119893243944 1
    "NESTLE 'N'" 20037  .0028409110016039  .0057236881178414 1
    "NESTLE 'N'" 20038  .0049522563184663  .0032223080762648 1
    "NESTLE 'N'" 20039  .0007054674013925 -.0031941157300339 1
    "NESTLE 'N'" 20040  .0084270161618801  .0097205484460905 1
    "NESTLE 'N'" 20041 -.0006995453240855 -.0043750080276395 1
    "NESTLE 'N'" 20044 -.0007000350303376  .0013159696020317 1
    "NESTLE 'N'" 20045   .002797204621061   .005082808928689 1
    "NESTLE 'N'" 20046  .0013956736389748  .0012229855957888 1
    "NESTLE 'N'" 20047  .0006971070341557  .0007143866871528 1
    "NESTLE 'N'" 20048  .0048661896511729   .010028589087032 1
    "NESTLE 'N'" 20051 -.0048661896511728  -.002430116097126 1
    "NESTLE 'N'" 20052 -.0020927806731306 -.0017424215443522 1
    "NESTLE 'N'" 20053   .003485538558434  .0017898895931208 1
    "NESTLE 'N'" 20054  .0041666726948461  .0077204751838029 1
    "NESTLE 'N'" 20055  .0055286941103169  .0023315606463968 1
    "NESTLE 'N'" 20058  .0048126596844157 -.0004678454708696 1
    "NESTLE 'N'" 20059                  0 -.0008334819572092 1
    "NESTLE 'N'" 20060 -.0082645098498935  .0032566931044356 1
    "NESTLE 'N'" 20061 -.0027700848738156 -.0054903908671599 1
    "NESTLE 'N'" 20062  .0055325175697257  .0103301225956557 1
    "NESTLE 'N'" 20065 -.0020711087831363 -.0034369768895232 1
    "NESTLE 'N'" 20066 -.0097222988033119 -.0142439346850057 1
    "NESTLE 'N'" 20067  -.002095704574219  -.003381989498622 1
    "NESTLE 'N'" 20068  .0027932979056127  .0042025211674284 1
    "NESTLE 'N'" 20069 -.0161690693067518 -.0182102004549737 1
    "NESTLE 'N'" 20072 -.0207669475251988 -.0207331640419422 1
    "NESTLE 'N'" 20073  .0143680632669202  .0094026549558896 1
    "NESTLE 'N'" 20074 -.0014275519911853 -.0021911099819013 1
    "NESTLE 'N'" 20075  .0198026272961797  .0266731348691425 1
    "NESTLE 'N'" 20076  .0118344576470028 -.0040990977023607 1
    "NESTLE 'N'" 20079  .0055210630237505  .0063532678724954 1
    "NESTLE 'N'" 20080  .0048060511320992 -.0013048932016547 1
    "NESTLE 'N'" 20081                  0                  0 1
    "NESTLE 'N'" 20082                  0                  0 1
    "NESTLE 'N'" 20083                  0                  0 1
    "NESTLE 'N'" 20086  .0034188067487855  .0014266554333746 1
    "NESTLE 'N'" 20087 -.0041039729283821 -.0056810261837974 1
    "NESTLE 'N'" 20088                  0                  0 1
    "NESTLE 'N'" 20089                  0                  0 1
    "NESTLE 'N'" 20090                  0                  0 1
    "NESTLE 'N'" 20093 -.0158897989146163 -.0049681447467889 1
    "NESTLE 'N'" 20094 -.0069881486339283 -.0072283302960199 1
    "NESTLE 'N'" 20095  .0035001785822096  .0029659155483526 1
    "NESTLE 'N'" 20096  .0180060266387539  .0264819372250905 1
    "NESTLE 'N'" 20097 -.0027491426249218 -.0037258769827564 1
    "NESTLE 'N'" 20100  .0082248578808848  .0051778257242762 1
    "NESTLE 'N'" 20101  .0155776939418696  .0143896270926776 1
    "NESTLE 'N'" 20102 -.0033658732551051  -.009460231137353 1
    "NESTLE 'N'" 20103 -.0640441502144893 -.0907034904784465 1
    "NESTLE 'N'" 20104 -.0707403150112229 -.0614934628682389 1
    "NESTLE 'N'" 20107  .0348784406194071  .0315481139923933 1
    "NESTLE 'N'" 20108 -.0029850768434532  .0031986938601383 1
    "NESTLE 'N'" 20109 -.0135442251077573 -.0210479462713971 1
    "NESTLE 'N'" 20110  .0045351551653911 -.0011331814059027 1
    "NESTLE 'N'" 20111  .0311829274366881   .020009776168187 1
    "NESTLE 'N'" 20114   .011628037995119  .0164413967293751 1
    "NESTLE 'N'" 20115  .0179023757210654  .0127396513307439 1
    "NESTLE 'N'" 20116 -.0135764857739428 -.0109212500589735 1
    "NESTLE 'N'" 20117  .0185322481289277  .0147839096884779 1
    "NESTLE 'N'" 20118 -.0049557623549848 -.0059701243940975 1
    "NESTLE 'N'" 20121  .0091840984645059  .0052419693099635 1
    "NESTLE 'N'" 20122 -.0021119332031434  .0027166122695206 1
    "NESTLE 'N'" 20123  .0105153439995229  .0183014034612103 1
    "NESTLE 'N'" 20124 -.0062959284568148 -.0074531493716451 1
    "NESTLE 'N'" 20125 -.0028109646056503  .0050979809003865 1
    "NESTLE 'N'" 20128  .0014064699927518  .0051277309449562 1
    "NESTLE 'N'" 20129  .0042075798400151 -.0013586391588064 1
    "NESTLE 'N'" 20130 -.0077274708377946 -.0049610002330397 1
    "NESTLE 'N'" 20131 -.0042402890388856  .0038711324703775 1
    "NESTLE 'N'" 20132 -.0042583456825771  .0047442568600064 1
    "NESTLE 'N'" 20135  .0035498794822038  .0069923871124588 1
    "NESTLE 'N'" 20136  .0091711401191071  .0040250860160916 1
    "NESTLE 'N'" 20137  -.001405481608735   .006026730435302 1
    "NESTLE 'N'" 20138  .0125787822068602  .0112391012049387 1
    "NESTLE 'N'" 20139 -.0013898542890542 -.0009003870248889 1
    "NESTLE 'N'" 20142  .0165521020287317  .0095714966875206 1
    "NESTLE 'N'" 20143  .0040955688647372  .0007705027020317 1
    "NESTLE 'N'" 20144  .0013614705983209 -.0007782998383663 1
    "NESTLE 'N'" 20145  .0148551009909241  .0079735887537756 1
    "NESTLE 'N'" 20146 -.0026845653706689 -.0038706825665697 1
    "NESTLE 'N'" 20149  .0053619431413854  .0045555694599729 1
    "NESTLE 'N'" 20150 -.0026773777707164 -.0112169887786511 1
    "NESTLE 'N'" 20151  .0106667678041954  .0042145959401385 1
    "NESTLE 'N'" 20152  .0059504307806307  .0046707542020157 1
    "NESTLE 'N'" 20153  .0039473735466298  .0050158457828439 1
    "NESTLE 'N'" 20156 -.0032883949395866 -.0036575496823017 1
    "NESTLE 'N'" 20157 -.0079365495957364 -.0025643891757088 1
    "NESTLE 'N'" 20158                  0  .0091032369507206 1
    "NESTLE 'N'" 20159 -.0026595760357588  .0014901758706779 1
    "NESTLE 'N'" 20160  .0039867162438214  .0039626159120275 1
    "NESTLE 'N'" 20163  .0066094093876738   .008814231945664 1
    "NESTLE 'N'" 20164 -.0026385239581812 -.0041843039766992 1
    "NESTLE 'N'" 20165  .0065833022491974  .0062564042653923 1
    "NESTLE 'N'" 20166   .004582659411092  .0077741675779324 1
    "NESTLE 'N'" 20167 -.0006533812712026  .0072428442577012 1
    end
    format %td date


    Code error


    My Code : eventstudy2 security_id date using security_returns_file, returns(security_returns) model(FM) marketfile(security_returns_file) marketreturns(market_return) replace

    Generating dateline ...
    ...succeeded

    Preparation of event list ...
    ...succeeded

    Preparation of security return data...
    variables date __000005 do not uniquely identify observations in the using data
    r(459);
    Attached Files

  • #2
    I have two thoughts: One, did you xtset the data properly? in fact, you almost certainly couldn't have: xtset won't work if your data have repeating time values, and will instead issue an error saying so.

    Two: You write you removed duplicates. How? show me the exact code you used.

    Comment


    • #3
      I have actually not used xtset data. Could you kindly explain why i should?

      The duplicate command i have used is as follows ( I have also attached the pictures)

      First i run the command : duplicates list security_returns date
      2nd i run the command : duplicates drop security_returns date , force

      Because it says the error is in the using file , my understanding (correct me i am wrong) is that the error exists in the security_returns_file .

      Attached Files

      Comment


      • #4
        I don't want to see a picture, and I won't look at it. Use the code delimiters in the text box to show me what you did.

        Anyways, xtset is just sort of a definitional thing here. You're working with panel data, so you should have Stata know that you're working with panel data. My point is that you need a unique ID to identify your actual unit of analysis. You cannot get around this problem, you need one number to uniquely ID each group you have and to index that to your time variable.

        Comment


        • #5
          Code:
           duplicates list security_returns date
          and then i use the command

          Code:
           duplicates drop security_returns date , force
          However, even after dropping the duplicates it gives the same error.

          I do not think xtset would apply to my data and I have read the manual help by Thomas Kaspereit (2021) and it does not require it.
          Last edited by Faiza Zafar; 02 Feb 2022, 06:17.

          Comment


          • #6
            How do you know eventstudy2 doesn't require the data being xtset?

            The error is
            variables date __000005 do not uniquely identify observations in the using data
            Typically with causal panel estimators, this error is issued within the context of ensuring that the panelvar and timevar uniquely ID each other so that the analysis can be estimated properly. I mean that's what's needed in this sort of analysis, the panelvar and timevar to index to each other perfectly.

            Comment


            • #7
              I have tried to use xtset with my data by running the code
              Code:
              xtset security_id date
              however , it says the following error : repeated time values within panel .

              Any other advise moving forward ?
              Currently , I am trying to enter each company one by one and then conduct eventstudy2 command.

              Comment


              • #8
                Well........ the issue here is that security_id isn't your panel variable. market_id is. In the example you provided, the unique ID for NESTLE is the marekt_id variable, since presumably it IDs the unique company associated with the security returns.

                Comment


                • #9
                  when i try to use the command
                  Code:
                  xtset market_id date
                  it gives the same error "repeated time values within panel" which is because some companies are from the same market so it does not consider it to be unique.
                  What advise would you give? I can share more data/ material if needed. I am stuck on this issue for quite a while

                  Comment


                  • #10
                    The solution then would be to
                    Code:
                    egen id = group( security_id market_id)
                    
                    xtset id date, d
                    Assuming a company can't be in multiple markets

                    Comment


                    • #11
                      What does d mean in this command?
                      Code:
                       xtset id date, d
                      I have tried the command
                      Code:
                       egen id = group( security_id market_id)
                      however it still gives me the same error "repeated time values within panel".

                      Like you have mentioned a company cannot be in multiple markets ,the companies in my sample are not in multiple markets, however does it make a difference if there are multiple events for same company in a market?

                      Comment


                      • #12
                        Faiza:
                        the easiest (but possible unsatisfactory) fix is to -xset- your dataset with -panelid- only:
                        Code:
                        xtset market_id
                        Unfortunately, this fix comes at the cost of making time-series related operators unfeasible.

                        As an aside, from the contents of your previous messages I take the liberty to point you out to .-xtset- entry, Stata .pdf manual and any decent textbook on panel data econometrrics and/or longitudinal data analysis, if you actually have panel data.
                        Kind regards,
                        Carlo
                        (Stata 19.0)

                        Comment


                        • #13
                          Thanks so much Carlo!

                          Comment


                          • #14
                            Dear Faiza,

                            Thank you for using eventstudy2.

                            eventstudy2 is not based on panel data, thus xtset -ting the data is not required.

                            Nevertheless, the data has to be free of duplicates ....

                            1) in terms of firm ids and event dates (this refers to your event list, which is the data you have in memory while executing)
                            2) in terms of firm ids and dates (this refers to the security returns file)
                            2) in terms of market_id and dates (the refers to the market returns file)

                            I suggest to do the following:

                            a) please get the example file that come with eventstudy2: net get eventstudy2 (copies these files in your current working directory: e.g. earnings_surprises.dta etc.)
                            b) make the sample study run on your machine; there are examples at the end of eventstudy2's helpfile (help eventstudy2)
                            c) adapt the data structure of your study to the data structure of the sample files. I do not understand if the data you posted above is your security returns or market file. It has both security returns and market returns. This should not be the case. Security and market returns are to be held in distinct data sets.
                            d) check that all three input files are free in terms of duplicates using the "isid" command (no error is good news):
                            -- isid [security_id] [event date] for the event list file
                            -- isid [security_id] [date when security return is observed] for the security returns file
                            -- isid [market_id] [date when the market return is observed] for the market index file

                            e) Try again running your study
                            f) If problems prevail, please post here and again send a personal email with the link to this post.

                            Best
                            Thomas

                            Comment


                            • #15
                              Thank you Thomas! This is really helpful. I was quite confused whether my data needs to be in panel data form so thanks for calrfiying that as well.
                              I will incorporate your suggestions and post any problem here accordingly.

                              Comment

                              Working...
                              X